package com.scetop.bank;

public class CheckingAccount extends Account{

    private double overdraftProtection = -1;
    private SavingsAccount protectedBy;
    public CheckingAccount(double balance){
        super(balance);}
//        this.protectedBy = protectedBy;
    public CheckingAccount(double balance, SavingsAccount protectedBy){
        super(balance);
        this.protectedBy = protectedBy;
    }
//    public boolean withdraw(double amt){
//        if (balance+)
//            return true;
//        }


    @Override
    public boolean withdraw(double amt) {
        if (balance >= amt){
            balance -= amt;
        }else {
            if (protectedBy.getBalance() >= (amt - balance)) {
                protectedBy.withdraw(amt - balance);
                balance = 0;
            } else {
                return false;
            }
        }
        return true;
    }
}
